package com.ygj.documentProcessing.action;

import static com.base.common.GlobaConstants.ACTION_RESULT_DATA;
import static com.base.common.GlobaConstants.ASYNCHRONOUS;
import static com.base.common.GlobaConstants.CONTENT_TYPE;
import static com.base.common.GlobaConstants.CONTENT_TYPE_JSON;
import static com.base.common.GlobaConstants.JSON;
import static com.base.common.GlobaConstants.ROOT;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.base.common.action.AbstractBaseAction;
import com.base.common.bean.ActionResult;
import com.cjy.common.bean.OpAttributes;
import com.ygj.base.common.persistent.model.Notes;
import com.ygj.documentProcessing.service.DocumentProcessingService;

/**
 * document processing action
 * 
 * @author Kat Colin
 *
 */

@Action("/documentProcessing")
@Results({ @Result(name = ASYNCHRONOUS, type = JSON, params = { ROOT,
		ACTION_RESULT_DATA, CONTENT_TYPE, CONTENT_TYPE_JSON }) })
public class DocumentProcessingAction extends AbstractBaseAction{

	private static final long serialVersionUID = -67325984602822077L;

	private static final Logger log = LoggerFactory.getLogger(DocumentProcessingAction.class);

	@Resource
	private DocumentProcessingService documentProcessingService;
	
	private String username;
	
	private String fno;
	
	private String fmen;
	
	private String ftitle;
	
	private String fsp;
	
	private String fps;
	
	private String ffb;
	
	private String rowguid;
	
	private String fbm;
	
	private String oldFsp;
	
	private String newFsp;
	
	private String newFfb;
	
	private String fmen1;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getFno() {
		return fno;
	}

	public void setFno(String fno) {
		this.fno = fno;
	}

	public String getFmen() {
		return fmen;
	}

	public void setFmen(String fmen) {
		this.fmen = fmen;
	}

	public String getFtitle() {
		return ftitle;
	}

	public void setFtitle(String ftitle) {
		this.ftitle = ftitle;
	}

	public String getFsp() {
		return fsp;
	}

	public void setFsp(String fsp) {
		this.fsp = fsp;
	}

	public String getFps() {
		return fps;
	}

	public void setFps(String fps) {
		this.fps = fps;
	}

	public String getFfb() {
		return ffb;
	}

	public void setFfb(String ffb) {
		this.ffb = ffb;
	}

	public String getRowguid() {
		return rowguid;
	}

	public void setRowguid(String rowguid) {
		this.rowguid = rowguid;
	}

	public String getFbm() {
		return fbm;
	}

	public void setFbm(String fbm) {
		this.fbm = fbm;
	}

	public String getOldFsp() {
		return oldFsp;
	}

	public void setOldFsp(String oldFsp) {
		this.oldFsp = oldFsp;
	}

	public String getNewFsp() {
		return newFsp;
	}

	public void setNewFsp(String newFsp) {
		this.newFsp = newFsp;
	}

	public String getNewFfb() {
		return newFfb;
	}

	public void setNewFfb(String newFfb) {
		this.newFfb = newFfb;
	}

	public String getFmen1() {
		return fmen1;
	}

	public void setFmen1(String fmen1) {
		this.fmen1 = fmen1;
	}

	@Action("/queryDocumentProcessingTotalCounts")
	public String queryDocumentProcessingTotalCounts() {
		try {
			actionResult = new ActionResult(new OpAttributes().add("code", 1).add("result", new OpAttributes().add("totalCounts",
					documentProcessingService.queryDocumentProcessingTotalCounts(username))));
//			actionResult = new ActionResult(new OpAttributes().add("code", 1));
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.toString());
			actionResult = new ActionResult(new OpAttributes().add("code", 0));
		}
		return returnType();
	}

	@Action("/queryDocumentProcessing")
	public String queryDocumentProcessing() {
		try {
			actionResult = new ActionResult(new OpAttributes().add("code", 1).add("result",
					documentProcessingService.queryDocumentProcessing(username)));
		} catch (Exception e) {
			log.error("queryOfficialDocumentSign exception", e);
			e.printStackTrace();
			actionResult = new ActionResult(new OpAttributes().add("code", 0));
		}
		return returnType();
	}

	@Action("/queryDocumentProcessingDetail")
	public String queryDocumentProcessingDetail() {
		try {
			actionResult = new ActionResult(new OpAttributes().add("code", 1).add("result",
					documentProcessingService.queryDocumentProcessingDetail(fno)));
		} catch (Exception e) {
			log.error("queryOfficialDocumentSignDetail exception", e);
			e.printStackTrace();
			actionResult = new ActionResult(new OpAttributes().add("code", 0));
		}
		return returnType();
	}

	@Action("/documentProcessingApprove")
	public String approve() {
		try {
			Notes notes = new Notes();
			notes.setFbm(fbm);
			notes.setRowguid(rowguid);
			notes.setFfb(ffb);
			notes.setFps(fps);
			notes.setFsp(fsp);
			notes.setFno(fno);
			notes.setFtitle(ftitle);
			// System.out.println("hh");
			// return new OpAttributes().add("code", 1);
			actionResult = new ActionResult(new OpAttributes().add("code", documentProcessingService.approve(fmen, notes)));
		} catch (Exception e) {
			log.error("approve exception", e);
			e.printStackTrace();
			actionResult = new ActionResult(new OpAttributes().add("code", 0));
		}
		return returnType();
	}

	@Action("/updateFsp")
	public String updateFsp(){
		try {
			// System.out.println("hh");
			// return new OpAttributes().add("code", 1);
			actionResult = new ActionResult(new OpAttributes().add("code",
					documentProcessingService.updateFsp(fmen, fno, ftitle, fbm, oldFsp, newFsp, newFfb)));
		} catch (Exception e) {
			log.error("approve exception", e);
			e.printStackTrace();
			actionResult = new ActionResult(new OpAttributes().add("code", 0));
		}
		System.out.println(actionResult.getData());
		return returnType();
	}

	@Action("/backToTheDrafters")
	public String backToTheDrafters() {
		try {
			Notes notes = new Notes();
			notes.setFtitle(ftitle);
			notes.setFno(fno);
			notes.setFmen1(fmen1);
			notes.setFps(fps);
			// System.out.println("hh");
			actionResult = new ActionResult(new OpAttributes().add("code", documentProcessingService.backToTheDrafters(fmen, notes)));
		} catch (Exception e) {
			log.error("backToTheDrafters exception", e);
			e.printStackTrace();
			actionResult = new ActionResult(new OpAttributes().add("code", 0));
		}
		
		return returnType();
	}

	@Action("/cancelTheOrderToLast")
	public String cancelTheOrderToLast() {
		try {
		
			Notes notes = new Notes();
			notes.setFtitle(ftitle);
			notes.setFno(fno);
			notes.setFps(fps);
			notes.setFsp(fsp);
			notes.setFmen1(fmen1);
			actionResult = new ActionResult(new OpAttributes().add("code", documentProcessingService.cancelTheOrderToLast(fmen, notes)));
		} catch (Exception e) {
			log.error("cancelTheOrderToLast exception", e);
			e.printStackTrace();
			actionResult = new ActionResult(new OpAttributes().add("code", 0));
		}
		
		return returnType();
	}
	
}
